package com.fesine.scheduler;

import com.fesine.scheduler.jobs.ScheduledJobWithMysql;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2017/2/28 14:35
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/2/28 14:35
 */
public class ScheduleJob {


    public static void main(String[] args) {
        JobDetail jd = newJob(ScheduledJobWithMysql.class).withIdentity(ScheduledJobWithMysql.class
                .getSimpleName()).storeDurably().build();
        TriggerBuilder tb = newTrigger().withIdentity(ScheduledJobWithMysql.class.getSimpleName(),"TRIGGER_DEFAULT");
        tb.withSchedule(cronSchedule("0 0/1 * ? * *"));
        tb.startNow();
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            if (scheduler.checkExists(jd.getKey())) {
                scheduler.deleteJob(jd.getKey());
            }
            //scheduler.scheduleJob(jd, tb.build());
            //scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
